<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>element.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_graphics_element.js.html">element.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2007 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>
<a name="line16"></a>/**
<a name="line17"></a> * @fileoverview A thin wrapper around the DOM element returned from
<a name="line18"></a> * the different draw methods of the graphics implementation, and
<a name="line19"></a> * all interfaces that the various element types support.
<a name="line20"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line21"></a> * @author yoah@google.com (Yoah Bar-David)
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>goog.provide(&#39;goog.graphics.Element&#39;);
<a name="line26"></a>
<a name="line27"></a>goog.require(&#39;goog.events&#39;);
<a name="line28"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line29"></a>goog.require(&#39;goog.graphics.AffineTransform&#39;);
<a name="line30"></a>goog.require(&#39;goog.math&#39;);
<a name="line31"></a>
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>/**
<a name="line35"></a> * Base class for a thin wrapper around the DOM element returned from
<a name="line36"></a> * the different draw methods of the graphics.
<a name="line37"></a> * You should not construct objects from this constructor. The graphics
<a name="line38"></a> * will return the object for you.
<a name="line39"></a> * @param {Element} element  The DOM element to wrap.
<a name="line40"></a> * @param {goog.graphics.AbstractGraphics} graphics  The graphics creating
<a name="line41"></a> *     this element.
<a name="line42"></a> * @constructor
<a name="line43"></a> * @extends {goog.events.EventTarget}
<a name="line44"></a> * @suppress {visibility} Accessing private field of superclass (see TODO).
<a name="line45"></a> */
<a name="line46"></a>goog.graphics.Element = function(element, graphics) {
<a name="line47"></a>  goog.events.EventTarget.call(this);
<a name="line48"></a>  this.element_ = element;
<a name="line49"></a>  this.graphics_ = graphics;
<a name="line50"></a>  // Overloading EventTarget field to state that this is not a custom event.
<a name="line51"></a>  // TODO(user) Should be handled in EventTarget.js (see bug 846824).
<a name="line52"></a>  this.customEvent_ = false;
<a name="line53"></a>};
<a name="line54"></a>goog.inherits(goog.graphics.Element, goog.events.EventTarget);
<a name="line55"></a>
<a name="line56"></a>
<a name="line57"></a>/**
<a name="line58"></a> * The graphics object that contains this element.
<a name="line59"></a> * @type {goog.graphics.AbstractGraphics?}
<a name="line60"></a> * @private
<a name="line61"></a> */
<a name="line62"></a>goog.graphics.Element.prototype.graphics_ = null;
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * The native browser element this class wraps.
<a name="line67"></a> * @type {Element}
<a name="line68"></a> * @private
<a name="line69"></a> */
<a name="line70"></a>goog.graphics.Element.prototype.element_ = null;
<a name="line71"></a>
<a name="line72"></a>
<a name="line73"></a>/**
<a name="line74"></a> * The transformation applied to this element.
<a name="line75"></a> * @type {goog.graphics.AffineTransform?}
<a name="line76"></a> * @private
<a name="line77"></a> */
<a name="line78"></a>goog.graphics.Element.prototype.transform_ = null;
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * Returns the underlying object.
<a name="line83"></a> * @return {Element} The underlying element.
<a name="line84"></a> */
<a name="line85"></a>goog.graphics.Element.prototype.getElement = function() {
<a name="line86"></a>  return this.element_;
<a name="line87"></a>};
<a name="line88"></a>
<a name="line89"></a>
<a name="line90"></a>/**
<a name="line91"></a> * Returns the graphics.
<a name="line92"></a> * @return {goog.graphics.AbstractGraphics} The graphics that created the
<a name="line93"></a> *     element.
<a name="line94"></a> */
<a name="line95"></a>goog.graphics.Element.prototype.getGraphics = function() {
<a name="line96"></a>  return this.graphics_;
<a name="line97"></a>};
<a name="line98"></a>
<a name="line99"></a>
<a name="line100"></a>/**
<a name="line101"></a> * Set the transformation of the element.
<a name="line102"></a> * @param {number} x The x coordinate of the translation transform.
<a name="line103"></a> * @param {number} y The y coordinate of the translation transform.
<a name="line104"></a> * @param {number} rotate The angle of the rotation transform.
<a name="line105"></a> * @param {number} centerX The horizontal center of the rotation transform.
<a name="line106"></a> * @param {number} centerY The vertical center of the rotation transform.
<a name="line107"></a> */
<a name="line108"></a>goog.graphics.Element.prototype.setTransformation = function(x, y, rotate,
<a name="line109"></a>    centerX, centerY) {
<a name="line110"></a>  // TODO(robbyw): Add skew and scale.
<a name="line111"></a>
<a name="line112"></a>  this.transform_ = goog.graphics.AffineTransform.getRotateInstance(
<a name="line113"></a>      goog.math.toRadians(rotate), centerX, centerY).translate(x, y);
<a name="line114"></a>  this.getGraphics().setElementTransform(this, x, y, rotate, centerX, centerY);
<a name="line115"></a>};
<a name="line116"></a>
<a name="line117"></a>
<a name="line118"></a>/**
<a name="line119"></a> * @return {goog.graphics.AffineTransform} The transformation applied to
<a name="line120"></a> *     this element.
<a name="line121"></a> */
<a name="line122"></a>goog.graphics.Element.prototype.getTransform = function() {
<a name="line123"></a>  return this.transform_ ? this.transform_.clone() :
<a name="line124"></a>      new goog.graphics.AffineTransform();
<a name="line125"></a>};
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/** @override */
<a name="line129"></a>goog.graphics.Element.prototype.addEventListener = function(
<a name="line130"></a>    type, handler, opt_capture, opt_handlerScope) {
<a name="line131"></a>  goog.events.listen(this.element_, type, handler, opt_capture,
<a name="line132"></a>      opt_handlerScope);
<a name="line133"></a>};
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/** @override */
<a name="line137"></a>goog.graphics.Element.prototype.removeEventListener = function(
<a name="line138"></a>    type, handler, opt_capture, opt_handlerScope) {
<a name="line139"></a>  goog.events.unlisten(this.element_, type, handler, opt_capture,
<a name="line140"></a>      opt_handlerScope);
<a name="line141"></a>};
<a name="line142"></a>
<a name="line143"></a>
<a name="line144"></a>/** @override */
<a name="line145"></a>goog.graphics.Element.prototype.disposeInternal = function() {
<a name="line146"></a>  goog.graphics.Element.superClass_.disposeInternal.call(this);
<a name="line147"></a>  goog.events.removeAll(this.element_);
<a name="line148"></a>};
</pre>


</body>
</html>
